<%@ page contentType="text/html;charset=UTF-8"%>
<jsp:directive.include file="/WEB-INF/view/jsp/admin/includes/top.jsp" />
<h3>
	编辑积分规则
</h3>
<form id="inputForm" name="inputForm" onsubmit="return checkForm();"
	action="${ctx}/admin/creditRule!save.do" method="post">
	<input type="hidden" name="id" value="${creditRule.id}" />
	<table class="inputView">
		<tr>
			<td class="label" width="15%" align="right" valign="middle">
				周期类型：
			</td>
			<td class="value" valign="middle">
				<ul>
					<li id="li_0" onclick="show('0',this)"
						onmouseover="mouseOver(this)">
						<input class="radio" type="radio" name="cycle" value="0">
						&nbsp;一次
					</li>
					<li id="li_1" onclick="show('1',this)"
						onmouseover="mouseOver(this)">
						<input class="radio" type="radio" name="cycle" value="1">
						&nbsp;每天
					</li>
					<!--
							 	<li id="li_2" onclick="show('2',this)" onmouseover="mouseOver(this)">
							 		<input class="radio" type="radio" name="cycle" value="2" >&nbsp;整点
							 	</li>
							 	<li id="li_3" onclick="show('3',this)" onmouseover="mouseOver(this)">
							 		<input class="radio" type="radio" name="cycle" value="3" >&nbsp;间隔分钟
							 	</li>
							 	-->
					<li id="li_2" onclick="show('2',this)"
						onmouseover="mouseOver(this)" class="checked">
						<input class="radio" type="radio" name="cycle" value="2"
							checked="checked">
						&nbsp;不限
					</li>
				</ul>
			</td>
			<td>
				<div id="typeTip" style="width: 250px"></div>
			</td>
		</tr>

		<tr>
			<td class="label" width="15%" align="right" valign="middle">
				积分规则名称：
			</td>
			<td class="value" valign="middle">
				<input type="text" id="name" name="name" style="width: 180px;"
					value="${creditRule.name}" />
			</td>
			<td>
				<div id="typeTip" style="width: 250px"></div>
			</td>
		</tr>

		<tr>
			<td class="label" width="15%" align="right" valign="middle">
				积分动作：
			</td>
			<td class="value" valign="middle">
				<input type="text" id="action" name="action" style="width: 180px;"
					value="${creditRule.action}" />
			</td>
			<td>
				<div id="typeTip" style="width: 250px"></div>
			</td>
		</tr>

		<!-- 
					<tr id="trCycleTime" style="display: none">
						<td class="label" width="15%" align="right" valign="middle">
							间隔时间：
						</td>
						<td class="value" valign="middle">
							<input type="text" id="cycleTime" name="cycleTime" style="width: 180px;"
								value="<c:if test="${empty creditRule.id}">0</c:if><c:if test="${not empty creditRule.id}">${creditRule.cycleTime}</c:if>" />
						</td>
						<td>
							<div id="typeTip" style="width: 250px"></div>
						</td>
					</tr>
					-->
		<tr id="trRewardNum" style="display: none">
			<td class="label" width="15%" align="right" valign="middle">
				奖励次数：
			</td>
			<td class="value" valign="middle">
				<input type="text" id="rewardNum" name="rewardNum"
					style="width: 180px;"
					value="<c:if test="${empty creditRule.id}">0</c:if><c:if test="${not empty creditRule.id}">${creditRule.rewardNum}</c:if>" />
			</td>
			<td>
				<div id="typeTip" style="width: 250px"></div>
			</td>
		</tr>

		<c:forEach items="${creditTypeList}" var="creditType">
			<tr>
				<td class="label" width="15%" align="right" valign="middle">
					${creditType.title }：
				</td>
				<td class="value" valign="middle">
					<c:if test="${empty creditRule.creditRuleAmounts}">
						<input type="text" id="amout_${creditType.id }_"
							name="amout_${creditType.id }_" style="width: 180px;" value="0" />
					</c:if>
					<c:if test="${not empty creditRule.creditRuleAmounts}">
						<c:set var="containsFlag" value="1" />
						<c:forEach items="${creditRule.creditRuleAmounts}" var="creditRuleAmount">
						
							<c:if test="${creditRuleAmount.creditType.title == creditType.title}">
								<input type="text" id="amout_${creditType.id }"
									name="amout_${creditType.id}" style="width: 180px;"
									value="<c:forEach items="${creditRule.creditRuleAmounts}" var="creditRuleAmount"><c:if test="${creditRuleAmount.creditType.title == creditType.title}">${creditRuleAmount.amout}</c:if></c:forEach>" />
								<c:set var="containsFlag" value="0" />
							</c:if>
							
						</c:forEach>
						<c:if test="${containsFlag ==1}">
							<input type="text" id="amout_${creditType.id }_" name="amout_${creditType.id }_" style="width: 180px;" value="0" />
						</c:if>
					</c:if>
				</td>
				<td>
					<div id="typeTip" style="width: 250px"></div>
				</td>
			</tr>
		</c:forEach>

		<tr>
			<td class="label" width="15%" align="right" valign="middle">
			</td>
			<td class="value" valign="middle">
				<input type="submit" id="submitConfig" name="submitConfig"
					value="确认" />
				&nbsp;
				<input type="button" value="取消" onclick="history.back()" />
			</td>
		</tr>
	</table>
</form>
<jsp:directive.include
	file="/WEB-INF/view/jsp/admin/includes/bottom.jsp" />
<script type="text/javascript">
<!--
function show(i,parentTarget){
	//var cycleTime = $("#trCycleTime");
	var rewardNum = $("#trRewardNum");
	selectChild(parentTarget);
	$("li").removeClass("checked");
	//alert(parentTarget);
	parentTarget.className ="checked";
	if(i==0 || i==2){
		//cycleTime.hide();
		rewardNum.hide();
	}
	if(i==1){
		//cycleTime.hide();
		rewardNum.show();
	}
}

function selectChild(parentTarget){
	parentTarget.firstChild.checked="checked";
}

function mouseOver(target){
	target.style.cursor='hand';
}

function checkForm(){
	var nameValue = $("#name").val();
	var actionValue = $("#action").val();
	if(nameValue == ""){
		alert("积分规则名称不能为空");
		return false; 
	}
	if(actionValue == ""){
		alert("积分动作不能为空");
		return false; 
	}
}

//初始化 周期类型
var cycleType = '${creditRule.cycleType}';
var cycle;
if(cycleType=="One"){
	cycle="0";
}
if(cycleType=="EveryDay"){
	cycle="1";
}
if(cycleType=="NoLimit"){
	cycle="2";
}

var parentTarget = $("#li_"+cycle);
parentTarget.click();
//-->
</script>
